package org.wk.core.common.http;

import java.util.concurrent.atomic.AtomicBoolean;

import javax.net.ssl.SSLContext;

import org.wk.core.common.unitofwork.Processor;

/**
 * 
 * @ClassName	: LBSRequestProcess
 * @Package		：org.wk.core.web.http
 * @Author df.w 
 * @Create Time	：2018年5月2日 上午10:19:49
 * @Description	: 封装http请求的处理
 */
public abstract class LBSRequestProcess extends Processor{
	private LBSRequest lbsRequest;
	private AtomicBoolean isSSL = new AtomicBoolean(false);
	private SSLContext sslContext;
	public LBSRequestProcess(){}
	public LBSRequestProcess(SSLContext sslContext){
		isSSL.getAndSet(true);
	}
	@Override
	public Either<? extends Exception, Boolean> execute() {
		try{
			if(isSSL.get()){
				lbsRequest = new LBSRequestHttps(sslContext);
			}else{
				lbsRequest = new LBSRequestHttp();
			}
			process();
			return Either.right(Boolean.TRUE);
		}catch(Exception e){
			return Either.left(e);
		}
	}
	public LBSRequest getLbsRequest() {
		return lbsRequest;
	}
	public void setLbsRequest(LBSRequest lbsRequest) {
		this.lbsRequest = lbsRequest;
	}
	public SSLContext getSslContext() {
		return sslContext;
	}
	public void setSslContext(SSLContext sslContext) {
		this.sslContext = sslContext;
	}
}
